import logging

# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')


def calculate_translation_points(text: str) -> int:
    """
    计算翻译所需积分
    规则：每1个字符消耗5积分

    Args:
        text: 需要翻译的文本

    Returns:
        int: 需要消耗的积分数量
    """
    if not text:
        return 0

    # 计算字符数
    char_count = len(text)

    # 计算积分：每1个字符消耗5积分
    points_needed = char_count * 5

    logging.info(f"文本字符数: {char_count}，计算积分: {points_needed}")
    return points_needed


def calculate_text_statistics(source_text: str, translated_text: str) -> dict:
    """
    计算文本统计信息

    Args:
        source_text: 源文本
        translated_text: 翻译后的文本

    Returns:
        dict: 包含字符统计信息的字典
    """
    source_length = len(source_text)
    translated_length = len(translated_text)
    points_needed = calculate_translation_points(source_text)

    return {
        "source_char_count": source_length,
        "translated_char_count": translated_length,
        "points_needed": points_needed,
        "calculation_rule": "每字符消耗5积分"
    }